#!/bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始增量导入==============='
echo '========================================'

# ========== 全量 ==========

# 1、customer_relationship客户意向表---------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *,'${TD_DATE}' as dt from customer_relationship where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table customer_relationship \
--split-by id \
--m 100
wait

# 2、customer clue客户线索表-----------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from customer_clue where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table customer_clue \
--m 100 \
--split-by id
wait

# 3、Customer客户静态信息表----------------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from customer where 1=1 and \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table customer \
--split-by id \
--m 100


echo '========================================'
echo '=================success==============='
echo '========================================'